package com.whiteape.book.ui.adapter.holder;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.whiteape.book.R;
import com.whiteape.book.model.bo.CategoryDetailBo;
import com.whiteape.book.ui.base.adapter.ViewHolderImpl;
import com.whiteape.book.utils.StringUtils;

/**
 * Created by newbiechen on 17-6-2.
 */

public class SourceCategoryHolder extends ViewHolderImpl<CategoryDetailBo> {

    private ImageView mIvCover;
    private TextView mTvName;
    private TextView mTvAuthor;
    private TextView mTvSource;
    private TextView mTvDesc;

    @Override
    public void initView() {
        mIvCover = findById(R.id.search_book_iv_cover);
        mTvName = findById(R.id.search_book_tv_name);
        mTvAuthor = findById(R.id.search_book_tv_author);
        mTvSource = findById(R.id.search_book_tv_source);
        mTvDesc = findById(R.id.search_book_tv_desc);
    }

    @Override
    public void onBind(CategoryDetailBo data, int pos) {
        //显示图片
        Glide.with(getContext())
                .load(data.getCoverUrl())
                .placeholder(R.mipmap.no_cover_portrait)
//                .error(R.mipmap.ic_load_error)
                .into(mIvCover);

        mTvName.setText(data.getTitle());

        mTvAuthor.setText("作者：" + (StringUtils.isEmpty(data.getAuthor()) ? "未知" : data.getAuthor()));
        mTvSource.setText("网源：" + data.getSiteSourceBean().getSiteName());
        mTvDesc.setText(data.getDesc());
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_search_book;
    }
}
